using Gameplay.PVE.Entity;

namespace Gameplay.PVE
{
    public class AttrackAttackAction : SpecialActionBase
    {
        private UnitBase lockTarget;
        private UnitBase attractTarget;
        public override void Start(AddControlArg arg)
        {
            base.Start(arg);
            lockTarget = unit.Data.lockTarget;
            attractTarget = arg.attractAttackTarget;
            unit.Data.SetAttractAttackTarget(attractTarget);
            unit.Data.SetLockTarget(attractTarget);
        }

        public override void Update()
        {
            base.Update();
            unit.Data.SetAttractAttackTarget(attractTarget);
        }

        public override void Free()
        {
            unit.Data.SetAttractAttackTarget(null);
            if (lockTarget?.Data != null && !lockTarget.Data.isDead && unit.Data.lockTarget == attractTarget)
            {
                unit.Data.SetLockTarget(lockTarget);
            }
            base.Free();
        }
    }
}